
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="购票系统">
    <meta name="author" content="">
    <meta name="baidu-site-verification" content="PLcIgMGOd5" />
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">

    <title>购票系统</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Custom styles for this template -->
    <link href="assets/css/carousel.css" rel="stylesheet">
    <link href="assets/css/common.css" rel="stylesheet">
    <style type="text/css">
      body{
      	padding-top:70px;
      }
    </style>    

  </head>
  <!-- NAVBAR -->
  <body>
    <div id="app">
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="index.html">购票系统</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
        </div>
      </div>
    </nav>

    <!-- Wrap the rest of the page in another container to center all the content. -->
    <div class="container marketing">
      <!-- Three columns of text below the carousel-->
      <div class="row">
        <div class="col-md-12">
          <h3>{{ticket.departure}}-{{ticket.destination}}</h3>
          <p>价格：<span class="price">￥{{ticket.price}}</span></p>
        </div><!-- /.col-md-3 -->
      </div><!-- /.row -->

      <div class="row">
        <div class="col-md-2"></div>
        <div class="col-md-7">
        	  <div class="form-group">
			    <label for="realName">姓名</label>
			    <input class="form-control" id="realName" placeholder="姓名" v-model="order.realName">
			  </div>
			  <div class="form-group">
			    <label for="mobile">手机号码</label>
			    <input class="form-control" id="mobile" placeholder="手机号码" v-model="order.mobile">
			  </div>
			  <div class="form-group">
			    <label for="cardNo">身份证号码</label>
			    <input class="form-control" id="cardNo" placeholder="身份证号码" v-model="order.cardNo">
			  </div>
			  <div  class="form-group" style="display: flex; align-items: center">
			  <input class="form-control" style="width: 250px; margin-right: 20px" placeholder="投币金额" v-model="amount"> 找零{{amount - ticket.price > 0 ? amount - ticket.price : 0}}
			  <button @click="buy" class="btn btn-primary" style="margin-left: 20px">立即购买</button>
			  </div>
        </div>
      </div>
    </div>

    <!-- FOOTER -->
    <footer style="text-align: center">
      <p></p>
    </footer>
  </div>
  <!-- Bootstrap core JavaScript
  ================================================== -->
  <!-- Placed at the end of the document so the pages load faster -->
  <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://cdn.bootcss.com/vue/2.6.8/vue.min.js"></script>
  <!-- Just to make our placeholder images work. Don't actually copy the next line! -->
  <script src="assets/js/vendor/holder.min.js"></script>
  <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  <script src="assets/js/ie10-viewport-bug-workaround.js"></script>
  <script src="assets/js/common.js"></script>
	<script>   
    
	var app = new Vue({
	  el: '#app',
	  data: {
		ticket: {},
        user: null,
        amount: null,
        order: {
        	
        }
	  },
      methods: {
        getGoods: function(id){
          $.getJSON(domain + "/api/ticket/detail", {id: id}, function(r){
            if(r.code == 0){
              app.ticket = r.ticket;
            }
          })
        },
        buy: function(){
          var data = {
            amount: app.amount,
            ticketId: app.ticket.id,
            realName: app.order.realName,
            mobile: app.order.mobile,
            cardNo: app.order.cardNo,
            change: app.amount - app.ticket.price
          }
          
          if(data.change < 0){
        	  alert("金额不足");
        	  return;
          }

          $.ajax({
            type: "POST",
              url: domain + "/api/order/save",
              contentType: "application/json",
              headers: {
              },
              data: JSON.stringify(data),
              success: function(r){
                if(r.code === 0){
                alert("下单成功")
              }else{
                alert(r.msg);
              }
            }
          });
        }
      },
      created: function(){
        var id = T.p("id");
        this.getGoods(id);
        var user = localStorage.getItem("fuser");
        if(user){
          this.user = JSON.parse(user);
        }
      }
	})
	</script>
  </body>
</html>
